<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>${siteName!""}|借阅管理-${title!""}</title>
<#include "../common/header.ftl"/>
    <style>
        td {
            vertical-align: middle;
        }
    </style>
</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">

            <!-- logo -->
            <div id="logo" class="sidebar-header">
                <a href="index.html"><img src="/admin/images/logo-sidebar.png" title="${siteName!""}"
                                          alt="${siteName!""}"/></a>
            </div>
            <div class="lyear-layout-sidebar-scroll">
        <#include "../common/left-menu.ftl"/>
            </div>

        </aside>
        <!--End 左侧导航-->

    <#include "../common/header-menu.ftl"/>

        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <div class="container-fluid">

                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-toolbar clearfix">
                <#include "../common/third-menu.ftl"/>
                            </div>
                            <div class="card-body">

                                <div class="table-responsive">
                                    <table class="table table-bordered">
                                        <thead>
                                        <tr>
                                            <th>
                                                <label class="lyear-checkbox checkbox-primary">
                                                    <input type="checkbox" id="check-all"><span></span>
                                                </label>
                                            </th>
                                            <th>学号</th>
                                            <th>用户</th>
                                            <th>图书编号</th>
                                            <th>图书名称</th>
                                            <th>状态</th>
                                            <th>数量</th>
                                            <th>借出时间</th>
                                            <th>预计归还时间</th>
                                            <th>归还时间</th>
                                            <th>是否逾期</th>
                                        </tr>
                                        </thead>
                                        <tbody>
                      <#if pageBean.content?size gt 0>
                      <#list pageBean.content as borrow>
                          <#--<#if borrow.student.id == id>-->
                          <tr>
                              <td style="vertical-align:middle;">
                                  <label class="lyear-checkbox checkbox-primary">
                                      <input type="checkbox" name="ids[]" value="${borrow.id}"><span></span>
                                  </label>
                              </td>
                              <td style="vertical-align:middle;">${borrow.student.studentId}</td>
                              <td style="vertical-align:middle;">${borrow.student.studentName}</td>
                              <td style="vertical-align:middle;">${borrow.book.id}</td>
                              <td style="vertical-align:middle;">${borrow.book.bookName}</td>
                              <td style="vertical-align:middle;">
                              <#if borrow.borrowState == 1>
                                  <font class="text-success">已归还</font>
                              <#elseif borrow.borrowState == 0>
                                  <font class="text-warning">借阅中</font>
                              </#if>
                              </td>
                              <td style="vertical-align:middle;">${borrow.borrowNum}</td>
                              <td style="vertical-align:middle;">${borrow.borrowTime}</td>
                              <td style="vertical-align:middle;">${borrow.expectedReturnTime}</td>
                              <td style="vertical-align:middle;">${borrow.returnTime!""}</td>
                              <td style="vertical-align:middle;">
                                <#if borrow.overTime == 1>
                                    <font class="text-warning">已逾期</font>
                                <#else >
                                <font class="text-success">未逾期</font>
                                </#if>
                              </td>
                          </tr>
                          <#--</#if>-->
                      </#list>
                      <#else>
                    <tr align="center">
                        <td colspan="11">无图书借阅记录！</td>
                    </tr>
                      </#if>
                                        </tbody>
                                    </table>
                                </div>
                                <#if pageBean.total gt 0>
                <ul class="pagination ">
                  <#if pageBean.currentPage == 1>
                  <li class="disabled"><span>«</span></li>
                  <#else>
                  <li><a href="list?id=${id!""}&currentPage=1">«</a></li>
                  </#if>
                  <#list pageBean.currentShowPage as showPage>
                      <#if pageBean.currentPage == showPage>
                  <li class="active"><span>${showPage}</span></li>
                      <#else>
                  <li><a href="list?id=${id!""}&currentPage=${showPage}">${showPage}</a></li>
                      </#if>
                  </#list>
                  <#if pageBean.currentPage == pageBean.totalPage>
                  <li class="disabled"><span>»</span></li>
                  <#else>
                  <li><a href="list?id=${id!""}&currentPage=${pageBean.totalPage}">»</a></li>
                  </#if>
                    <li><span>共${pageBean.totalPage}页,${pageBean.total}条数据</span></li>
                </ul>
                                </#if>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>
<#include "../common/footer.ftl"/>
<script type="text/javascript" src="/admin/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="/admin/js/main.min.js"></script>
<script type="text/javascript">
    $(document).ready(function () {

    });

    function returnBook(url) {
        if ($("input[type='checkbox']:checked").length != 1) {
            showWarningMsg('请选择一条数据进行归还！');
            return;
        }
        var id = $("input[type='checkbox']:checked").val();
        $.confirm({
            title: '确定归还？',
            content: '归还后数据不可恢复，请慎重！',
            buttons: {
                confirm: {
                    text: '确认',
                    action: function () {
                        retBook(id, url);
                    }
                },
                cancel: {
                    text: '关闭',
                    action: function () {
                    }
                }
            }
        });
    }

    // //打开编辑页面
    // function edit(url){
    // 	if($("input[type='checkbox']:checked").length != 1){
    // 		showWarningMsg('请选择一条数据进行编辑！');
    // 		return;
    // 	}
    // 	window.location.href = url + '?id=' + $("input[type='checkbox']:checked").val();
    // }
    //你这个数量也没加
    //这个id是图书编号?  方法有问题的现在 数据都是假的
    //调用归还方法
    function retBook(id, url) {
        $.ajax({
            url: url,
            type: 'POST',
            data: {id: id},
            dataType: 'json',
            success: function (data) {
                if (data.code == 0) {
                    showSuccessMsg('图书归还成功!', function () {
                        $("input[type='checkbox']:checked");
                        window.location.reload()
                    })
                } else {
                    showErrorMsg(data.msg);
                }
            },
            error: function (data) {
                alert('网络错误!');
            }
        });
    }
</script>
</body>
</html>